package com.GlobalPaint.app.ui.Mine.Personal;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;

import com.GlobalPaint.app.R;
import com.GlobalPaint.app.bean.PersonalBean;
import com.GlobalPaint.app.bean.ReturnStatusResultEntity;
import com.GlobalPaint.app.utils.Constants;
import com.GlobalPaint.app.utils.DataManager;
import com.squareup.picasso.MemoryPolicy;
import com.squareup.picasso.NetworkPolicy;
import com.squareup.picasso.Picasso;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import de.hdodenhof.circleimageview.CircleImageView;

import static com.GlobalPaint.app.R.id.imge_touxiang;

public class PersonalZhanshi extends AppCompatActivity {

    @BindView(R.id.iv_goback)
    ImageView ivGoback;
    @BindView(R.id.tv_common_center)
    TextView tvCommonCenter;
    @BindView(imge_touxiang)
    CircleImageView imgeTouxiang;
    @BindView(R.id.tv_nick1)
    TextView tvNick1;
    @BindView(R.id.tv_name)
    TextView tvName;
    @BindView(R.id.ed_qq)
    TextView edQq;
    @BindView(R.id.ed_weixin)
    TextView edWeixin;
    @BindView(R.id.et_company)
    TextView etCompany;
    @BindView(R.id.sex)
    TextView sex;
    @BindView(R.id.rl_sex)
    RelativeLayout rlSex;
    @BindView(R.id.et_jianjie)
    TextView etJianjie;
    @BindView(R.id.scroll_view)
    ScrollView scrollView;
    private PersonalBean personalBean;
    int userid;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_personalzhanshi);
        ButterKnife.bind(this);
        tvCommonCenter.setText("详情");

         userid=getIntent().getIntExtra("userid",0);
        getInformation();
    }

    private void getInformation() {

        String url= Constants.JASON_SERVICE_URL+"user/getUserById?userid="+ userid;
        DataManager.getInst().getHttpRequestJsonClass(url, DataManager.userEntity.getCookie(), PersonalBean.class, new DataManager.Callback() {
            @Override
            public void onSuccess(Object o) {

                personalBean=(PersonalBean)o;
                if (personalBean.getStatus() == 1){
                    if(personalBean.getData() != null ){
                        String qq = personalBean.getData().getFQq() ==
                                null ? "" : personalBean.getData().getFQq();
                        String username = personalBean.getData().getFUsername() ==
                                null ? "" : personalBean.getData().getFUsername();
                        String Weixin = personalBean.getData().getFWeixin() ==
                                null ? "" : personalBean.getData().getFWeixin();
                        String Msn = personalBean.getData().getFNickName() ==
                                null ? "" : personalBean.getData().getFNickName();
                        String Company = personalBean.getData().getCompany() ==
                                null ? "" : personalBean.getData().getCompany();
                        String Bio = personalBean.getData().getFBio() ==
                                null ? "" : personalBean.getData().getFBio();
                        String Gender = personalBean.getData().getFGender() ==
                                null ? "" : personalBean.getData().getFGender();
                        String Url= personalBean.getData().getAvatar()== null?"wu":
                                personalBean.getData().getAvatar();
                        if(Url.equals("wu")){
                            Picasso.with(PersonalZhanshi.this).load(R.drawable.touxiang)
                                    .memoryPolicy(MemoryPolicy.NO_CACHE)
                                    .networkPolicy(NetworkPolicy.NO_CACHE)
                                    .placeholder(R.drawable.touxiang).into(imgeTouxiang);
                        }else {
                            Picasso.with(PersonalZhanshi.this).load(Constants.JASON_SERVICE_URL_TOUXIANG+Url)
                                    .memoryPolicy(MemoryPolicy.NO_CACHE)
                                    .networkPolicy(NetworkPolicy.NO_CACHE)
                                    .placeholder(R.drawable.touxiang).into(imgeTouxiang);
                        }
                        if (username.length() > 4) {
                            String phone1 = (username.substring(0, 3));
                            String phone2 = username.substring(username.length() - 3, username.length());
                            tvName.setText(phone1 + "***" + phone2);
                        }
                        edQq.setText(qq);
                        edWeixin.setText(Weixin);
                        tvNick1.setText(Msn);
                        etCompany.setText(Company);
                        etJianjie.setText(Bio);
                        if(Gender.equals("M")){
                            sex.setText("男");
                        }else {
                            sex.setText("女");
                        }

                    }
                }
                else {
                    Toast.makeText(PersonalZhanshi.this,personalBean.getMsg(),Toast.LENGTH_LONG).show();
                }
            }

            @Override
            public void onFailure(ReturnStatusResultEntity error) {
            }
        });
    }
    @OnClick({R.id.iv_goback, R.id.tv_common_center})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_goback:
                finish();
                break;
        }
    }
    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}
